package com.web.controller;


import com.web.entity.PersonHealthInfo;
import com.web.entity.Result;
import com.web.service.PersonHealthInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/personHealthInfo")
@CrossOrigin
public class PersonHealthInfoController {

    @Autowired
    private PersonHealthInfoService personHealthInfoService;

    //http://localhost:8080/personHealthInfo/getInfo?userId=2&recordDate='2025-09-25'
    @GetMapping("/getInfo")
    public Result list(PersonHealthInfo personHealthInfo) {
        PersonHealthInfo byUserIdAndDate = this.personHealthInfoService.findByUserIdAndDate(personHealthInfo);
        log.info("查询结果：{}", byUserIdAndDate);
        return Result.success(byUserIdAndDate);
    }

    //http://localhost:8080/personHealthInfo/add
    @PostMapping("/add")
    public Result add(@RequestBody PersonHealthInfo personHealthInfo){
        log.info("新增数据：{}", personHealthInfo);
        this.personHealthInfoService.insert(personHealthInfo);
        return Result.success("新增成功");
    }




}
